#include<cstdio>
#include<cstring>
const int maxn=1100;
int c[maxn][maxn];
int s;
int low(int x)
{
	return x&(x^(x-1));
}
int sum(int x,int y)
{
	int ans=0;
	for(int i=x;i>0;i-=low(i))
		for(int j=y;j>0;j-=low(j))
			ans+=c[i][j];
	return ans;
}
void add(int x,int y,int v)
{
	for(int i=x;i<=s;i+=low(i))
		for(int j=y;j<=s;j+=low(j))
			c[i][j]+=v;
}

int main()
{
	freopen("test.in","r",stdin);
	int op,x,y,a,l,b,r,t;
	while(scanf("%d",&op)!=EOF)
	{
		if(op==0)scanf("%d",&s);
		if(op==1)
		{
			scanf("%d%d%d",&x,&y,&a);
			x++;y++;
			add(x,y,a);
		}
		if(op==2)
		{
			scanf("%d%d%d%d",&l,&b,&r,&t);
			l++;b++;r++;t++;
			int ans=sum(r,t)-sum(l-1,t)-sum(r,b-1)+sum(l-1,b-1);
			printf("%d\n",ans);
		}
	}
	return 0;
}


